package com.kc.web.controller.business;

import com.kc.business.domain.BizGoodsBuyback;
import com.kc.business.service.IBizGoodsBuybackService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.constant.Constants;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * TODO
 * 商品回购
 *
 * @author zhangshuo
 * @version 1.0
 * @date 2020/10/13
 */
@RestController
@RequestMapping("/business/goodsBuyback")
public class BizGoodsBuybackController extends BaseController {
    @Resource
    IBizGoodsBuybackService goodsBuybackService;

    /**
     * 回购商品列表
     *
     * @param goodsBuyback
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:goodsBuyback:list')")
    @GetMapping("/list")
    public TableDataInfo getList(BizGoodsBuyback goodsBuyback) {
        startPage();
        goodsBuyback.setIsDeleted(0);
        return getDataTable(goodsBuybackService.getList(goodsBuyback));
    }

    @PreAuthorize("@ss.hasPermi('business:goodsBuyback:add')")
    @Log(title = "回购商品管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizGoodsBuyback goodsBuyback) {
        return toAjax(goodsBuybackService.add(goodsBuyback));
    }

    @PreAuthorize("@ss.hasPermi('business:goodsBuyback:edit')")
    @Log(title = "回购商品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizGoodsBuyback goodsBuyback) {
        return toAjax(goodsBuybackService.edit(goodsBuyback));
    }

    @PreAuthorize("@ss.hasPermi('business:goodsBuyback:remove')")
    @Log(title = "回购商品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{backId}")
    @RepeatSubmit
    public AjaxResult delete(@PathVariable Integer backId) {
        BizGoodsBuyback goodsBuyback = new BizGoodsBuyback();
        goodsBuyback.setBackId(backId);
        goodsBuyback.setIsDeleted(Constants.DELETE);
        return toAjax(goodsBuybackService.delete(goodsBuyback));
    }
}
